{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-21T12:55:44.710864900Z",
     "start_time": "2025-07-21T12:55:44.699341200Z"
    }
   },
   "outputs": [],
   "source": [
    "from gs_quant.session import GsSession\n",
    "from gs_quant.instrument import IRCapFloor, IRCap, IRFloor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-21T12:47:57.166676100Z",
     "start_time": "2025-07-21T12:47:55.177673500Z"
    }
   },
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Instrument - IRAssetSwapFxdFlt"
    ]
   },
   "outputs": [],
   "source": [
    "# Create an interest rate cap using IRCapFloor, setting cap_floor to \"Cap\"\n",
    "cap = IRCapFloor(\n",
    "    cap_floor=\"Cap\",\n",
    "    notional_currency=\"USD\",\n",
    "    notional_amount=1000,\n",
    "    effective_date='2025-07-18',\n",
    "    termination_date='2030-07-18',\n",
    "    floating_rate_option='USD-LIBOR-BBA',\n",
    "    floating_rate_designated_maturity='3m',\n",
    "    floating_rate_frequency='3m',\n",
    "    strike=0.015,  # 1. 5% floor rate\n",
    ")\n",
    "cap.resolve(in_place=False).to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cap.price()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "Compared that with the output of IRCap, we have similar result."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ircap = IRCap(\n",
    "    notional_currency=\"USD\",\n",
    "    notional_amount=1000,\n",
    "    effective_date='2025-07-15',\n",
    "    termination_date='2030-07-15',\n",
    "    floating_rate_option='USD-LIBOR-BBA',\n",
    "    floating_rate_designated_maturity='3m',\n",
    "    floating_rate_frequency='3m',\n",
    "    cap_rate=0.015,  # 1.5% cap rate\n",
    ")\n",
    "ircap.resolve(in_place=False).to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ircap.price()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create an interest rate cap using IRCapFloor, setting cap_floor to \"Floor\"\n",
    "floor = IRFloor(\n",
    "    notional_currency=\"USD\",\n",
    "    notional_amount=1000,\n",
    "    effective_date='2025-07-15',\n",
    "    termination_date='2030-07-15',\n",
    "    floating_rate_option='USD-LIBOR-BBA',\n",
    "    floating_rate_designated_maturity='3m',\n",
    "    floating_rate_frequency='3m',\n",
    "    floor_rate=0.015,  # 1.5% floor rate\n",
    ")\n",
    "floor.resolve(in_place=False).to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "floor.price()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Compare output with IRFloor function\n",
    "irfloor = IRFloor(\n",
    "    notional_currency=\"USD\",\n",
    "    notional_amount=1000,\n",
    "    effective_date='2025-07-15',\n",
    "    termination_date='2030-07-15',\n",
    "    floating_rate_option='USD-LIBOR-BBA',\n",
    "    floating_rate_designated_maturity='3m',\n",
    "    floating_rate_frequency='3m',\n",
    "    floor_rate=0.015,  # 1.5% cap rate\n",
    ")\n",
    "irfloor.resolve(in_place=False).to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "irfloor.price()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.1"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
